package com.aura.lyngen.core.saver;

import com.aura.lyngen.ai.model.HtmlCodeResult;
import com.aura.lyngen.exception.BusinessException;
import com.aura.lyngen.exception.ErrorCode;
import com.aura.lyngen.model.enums.CodeGenTypeEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName HtmlCodeFileSaverTemplate
 * @Description Html代码文件保存模板类
 * @Author ZJX
 * @Date 2025/9/1 17:05
 * @Version 1.0
 **/
public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
        writeContentToFile(baseDirPath, "index.html", result.getHtmlCode());
    }

    @Override
    protected void validateInput(HtmlCodeResult result) {
        super.validateInput(result);
//        校验HTML代码
        if (StringUtils.isBlank(result.getHtmlCode())) {
            throw new BusinessException(ErrorCode.PARAMS_NULL, "html代码不能为空");
        }
    }
}
